package com.gacu.viewer.client.algo.match;

//import com.google.gwt.core.client.GWT;
import com.gacu.viewer.client.algo.AbsAlgoWidget;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ImageBundle;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;

public class MatchAlgoConfigWidget extends AbsAlgoWidget{		
	private final static String DESCRIPTION = "This algorithm must be call with two parameters: 1-secondary structure, 2-primary sequence. It will return a secondary structure with the primary sequence set, where it is possible.";
    private final static String NAME = "Match Algorithm";
	
	private MatchDialog dialog;
	public boolean started;
	public SimplePanel imageContainer;
	public MatchAlgoImageBundle imagesBundle;
	
	public interface MatchAlgoImageBundle extends ImageBundle {
        @Resource("details.gif")
        public AbstractImagePrototype detailsButtonIcon();

        @Resource("redX.png")
        public AbstractImagePrototype cancelButtonIcon();
        
        @Resource("play.png")
        public AbstractImagePrototype playButtonIcon();
        
        @Resource("pause.png")
        public AbstractImagePrototype pauseButtonIcon();
        
        @Resource("check.png")
        public AbstractImagePrototype checkButtonIcon();
    }
	
	public MatchAlgoConfigWidget(int pxWidth)
	{
		HorizontalPanel hp;
		Image img;				
		
		imagesBundle = GWT.create(MatchAlgoImageBundle.class);
		hp = new HorizontalPanel();
		
		hp.setWidth(pxWidth + "px");
		
		started = false;
		
		hp.add(new Label(NAME));
		
		imageContainer =  new SimplePanel();
		
		hp.add(imageContainer);
		
		img = imagesBundle.playButtonIcon().createImage();//Image("Red_X.png");
		img.addClickHandler(new OptionClickHandler());
		imageContainer.add(img);
		
		img = imagesBundle.cancelButtonIcon().createImage();//Image("Red_X.png");
		img.addClickHandler(new CancelClickHandler());
		hp.add(img);
		
		dialog = new MatchDialog(this, new OptionClickHandler());
		
		initWidget(hp);
	}				
	
	private class CancelClickHandler implements ClickHandler
	{
		@Override
		public void onClick(ClickEvent event) {
			MatchAlgoConfigWidget.this.removeFromParent();
		}
	}
	
	public class OptionClickHandler implements ClickHandler
	{
		@Override
		public void onClick(ClickEvent event) {
			showOptions();
		}		
	}	
	
	public void showOptions()
	{
		dialog.center();
		dialog.show();
	}

	@Override
	public String getDescription() {
		return NAME;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return DESCRIPTION;
	}
}
